package com.liangdemo.web.设计模式.单例模式.静态内部类;

/**
 * 静态内部类
 * @AUTHOR: Mr.Liang
 * @DATE: 2023/5/6 11:13
 * @DESCRIPTION:
 */
public class SingletonTest01 {
    public static void main(String[] args) {

    }
}

class Singleton{
    private static volatile  Singleton instance;
    //构造器私有化
    private Singleton(){}
    //写一个静态内部类，该类中有一个静态属性
    private static class SingletonInstance{
        private static final  Singleton INSTANCE=new Singleton();
    }
    //提供一个静态的公有方法。直接返回SingletonInstance.INSTANCE;
    public static synchronized Singleton getInstance(){
        return SingletonInstance.INSTANCE;
    }

}